#!/usr/bin/env ruby

"""Utility to make a graphic file smaller"""

require 'optparse'
require 'date'

options = {}

option_parser = OptionParser.new do |opts|
  # switches requires no parameters
	opts.on("-f <file>", "--file", 'Graphic file') do | input_file |
		options[:file] = input_file
	end
end
  
option_parser.parse!

if options.length != 1
	puts option_parser.help
	exit 1
end

if options[:file]
  output_file = options[:file]
  if output_file.split(/\./).length != 2
    puts option_parser.help
    exit 1
  end
  
  prefix = output_file.split(/\./)[0]
  ext = output_file.split(/\./)[1]
  system('convert -resize 50% -quality 80 ' + options[:file] + ' ' + prefix + '_' + Date.today.to_s + '.' + ext)
end

